Correct statistics reports by zeroing counters on successful checkin. Lay groundwork...
authorrobertl <robertl>
Sun, 14 Feb 2010 05:33:36 +0000 (05:33 +0000)
committerrobertl <robertl>
Sun, 14 Feb 2010 05:33:36 +0000 (05:33 +0000)
gui/babeldata.h
gui/format.cpp
gui/format.h
gui/mainwindow.cpp
gui/serial_mac.cpp
gui/upgrade.cpp
gui/upgrade.h

index 14db1dce845261af1ce9b489a07b4ab60dfdf7e0..540e729fbe38b8eced12fe23e6d33a45da45d130 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: babeldata.h,v 1.3 2009/08/03 05:16:23 robertl Exp $
+// $Id: babeldata.h,v 1.4 2010/02/14 05:33:36 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -56,7 +56,8 @@ public:
     previewGmap(false),
     upgradeCheckMethod(0),
     upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0))),
-    installationUuid(QUuid::createUuid().toString())
+    installationUuid(QUuid::createUuid().toString()),
+    checkUpgradeOnStart(true)
   {
   };
   
@@ -135,6 +136,9 @@ public:
   QDateTime upgradeCheckTime;
   QString installationUuid;
 
+  // Global preferences.
+  bool checkUpgradeOnStart;
+
 };
 
 #endif
index 6ce2e2e706f5d6a04114d789d33af883076a7fad..54d92dc5b23c15c3a6d192d67e2d210663abd882 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: format.cpp,v 1.3 2010/01/17 01:42:10 robertl Exp $
+// $Id: format.cpp,v 1.4 2010/02/14 05:33:37 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -51,19 +51,18 @@ void Format::saveSettings(QSettings &settings)
 {
   saveOptions(settings, name+".input", inputOptions);
   saveOptions(settings, name+".output", outputOptions);
-  // TODO: Finish this; let's not corrupt the .plsts until we can start from zero.
-  if (getReadUseCount() || getWriteUseCount()) {    
-    settings.setValue(name + ".readcount", getReadUseCount());
-    settings.setValue(name + ".writecount", getWriteUseCount());
-  }
+  settings.setValue(name + ".readcount", getReadUseCount());
+  settings.setValue(name + ".writecount", getWriteUseCount());
+  settings.setValue(name+".hidden", isHidden());
 }
 
 void Format::restoreSettings(QSettings &settings)
 {
-  restoreOptions(settings, name+".input", inputOptions);
-  restoreOptions(settings, name+".output", outputOptions);
+  restoreOptions(settings, name + ".input", inputOptions);
+  restoreOptions(settings, name + ".output", outputOptions);
   bumpReadUseCount(settings.value(name + ".readcount").toInt());
   bumpWriteUseCount(settings.value(name + ".writecount").toInt());
+  hidden_ = settings.value(name + ".hidden", false).toBool();
 }
 
 void Format::setToDefault()
@@ -76,4 +75,4 @@ void Format::setToDefault()
     outputOptions[i].setSelected(false);
     outputOptions[i].setValue(QVariant());
   }
-}
\ No newline at end of file
+}
index 47032468e7181503f0248aa39ffd25fdcd9a62b7..b78b15215aa10467bb6ed9f3289022c8e3e69ea5 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: format.h,v 1.4 2010/01/17 21:57:00 robertl Exp $
+// $Id: format.h,v 1.5 2010/02/14 05:33:37 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -108,10 +108,11 @@ class Format
           writeRoutes(false),
           fileFormat(false),
           deviceFormat(false),
+           hidden_(false),
           extensions(QStringList()),
-     html(QString()),
-     readUseCount_(0),
-     writeUseCount_(0)
+           html(QString()),
+           readUseCount_(0),
+           writeUseCount_(0)
   {
     inputOptions.clear();
     outputOptions.clear();
@@ -130,6 +131,7 @@ class Format
     readWaypoints(readWaypoints), readTracks(readTracks), readRoutes(readRoutes),
     writeWaypoints(writeWaypoints), writeTracks(writeTracks), writeRoutes(writeRoutes),
     fileFormat(fileFormat), deviceFormat(deviceFormat),
+    hidden_(false),
     extensions(extensions),
     inputOptions(inputOptions),
     outputOptions(outputptions),
@@ -145,13 +147,13 @@ class Format
     readWaypoints(c.readWaypoints), readTracks(c.readTracks), readRoutes(c.readRoutes),
     writeWaypoints(c.writeWaypoints), writeTracks(c.writeTracks), writeRoutes(c.writeRoutes),
     fileFormat(c.fileFormat), deviceFormat(c.deviceFormat),
+    hidden_(false),
     extensions(c.extensions),
     inputOptions(c.inputOptions),
     outputOptions(c.outputOptions),
     html(c.html),
     readUseCount_(0),
     writeUseCount_(0)
-  
   {
   }
 
@@ -183,6 +185,7 @@ class Format
 
   bool isDeviceFormat() const { return deviceFormat; };
   bool isFileFormat() const { return   fileFormat; };
+  bool isHidden() const { return hidden_; };
   
   void saveSettings(QSettings &settings);
   void restoreSettings(QSettings &settings);
@@ -194,13 +197,16 @@ class Format
   void bumpWriteUseCount(int v) { writeUseCount_ += v; }
   int getReadUseCount()  const { return readUseCount_; }
   int getWriteUseCount() const { return writeUseCount_; }
-  void zeroUseCounts(void);
+  void zeroUseCounts(void) {
+    readUseCount_ = 0;
+    writeUseCount_= 0;
+  }
   
  private:
   QString name, description;
   bool readWaypoints, readTracks, readRoutes;
   bool writeWaypoints, writeTracks, writeRoutes;
-  bool fileFormat, deviceFormat;
+  bool fileFormat, deviceFormat, hidden_;
   QStringList extensions;
   QList<FormatOption>inputOptions;
   QList<FormatOption>outputOptions;
index 23cd8de4d88003f0e36e1a57e790a21d4e4f0c24..f09bc5d63ba4baaf17e0a704666d0c8488caa403 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: mainwindow.cpp,v 1.13 2010/01/17 01:42:10 robertl Exp $
+// $Id: mainwindow.cpp,v 1.14 2010/02/14 05:33:37 robertl Exp $
 //------------------------------------------------------------------------
 //
 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
@@ -106,6 +106,7 @@ static QString MakeOptionsNoLeadingComma(const QList<FormatOption>& options)
   return (str.length()) ? str.mid(1) : str;
 
 }
+
 //------------------------------------------------------------------------
 MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
 {
@@ -168,10 +169,12 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
 
   //--- Restore from registry
   restoreSettings();
-  upgrade = new UpgradeCheck();
-  upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, 
-                           bd.upgradeCheckTime, bd.installationUuid,
-                           formatList);
+
+  if (bd.checkUpgradeOnStart) {
+    upgrade = new UpgradeCheck(parent, formatList);
+    upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, 
+                             bd.upgradeCheckTime, bd.installationUuid);
+  }
 }
 
 //------------------------------------------------------------------------
@@ -247,7 +250,9 @@ void MainWindow::inputFileOptBtnClicked()
   ui.inputFormatCombo->clear();
   for (int i=0; i<indices.size(); i++) {
     int k = indices[i];
-    ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
+fprintf(stderr, "%s/%d\n", qPrintable(formatList[k].getName()), formatList[k].isHidden());
+    if (!formatList[k].isHidden())
+      ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
   }
   setComboToFormat(ui.inputFormatCombo, fmt, true);
   fmtChgInterlock = false;
@@ -263,7 +268,9 @@ void MainWindow::inputDeviceOptBtnClicked()
   ui.inputFormatCombo->clear();
   for (int i=0; i<indices.size(); i++) {
     int k = indices[i];
-    ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
+fprintf(stderr, "%s/%d\n", qPrintable(formatList[k].getName()), formatList[k].isHidden());
+    if (!formatList[k].isHidden())
+      ui.inputFormatCombo->addItem(formatList[k].getDescription(), QVariant(k));
   }
   setComboToFormat(ui.inputFormatCombo, fmt, false);
   fmtChgInterlock = false;
index 14097579851fed11048e4ea8dc0728b9eb431ca2..fc78d9ccd3bc0222dec897f0ccfbf043686072dc 100644 (file)
@@ -193,8 +193,6 @@ static kern_return_t GetModemPath(io_iterator_t serialPortIterator, char *bsdPat
             }
         }
 
-        printf("\n");
-
         // Release the io_service_t now that we are done with it.
        
 //             (void) IOObjectRelease(modemService);
index 0020b682ee48f5d57cb39a29368b1dad16c028b5..5fd7b7262e22159bb4d36a59c4fcec58bcd84383 100644 (file)
@@ -1,5 +1,5 @@
 // -*- C++ -*-
-// $Id: upgrade.cpp,v 1.19 2010/01/17 21:57:00 robertl Exp $
+// $Id: upgrade.cpp,v 1.20 2010/02/14 05:33:37 robertl Exp $
 /*
     Copyright (C) 2009, 2010  Robert Lipe, robertlipe@gpsbabel.org
 
 #include <QSysInfo>
 #include <QUrl>
 
-// static const bool testing = true;
+#if 0
+static const bool testing = true;
+#else
 static const bool testing = false;
+#endif
 
-UpgradeCheck::UpgradeCheck(QWidget *parent) :
+UpgradeCheck::UpgradeCheck(QWidget *parent, QList<Format> &formatList) :
   QObject(parent),
-  http(0)
+  http(0), formatList_(formatList), updateStatus_(updateUnknown)
 {
 }
 
@@ -112,13 +115,12 @@ QString UpgradeCheck::getOsVersion()
 UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentVersionIn,
                int checkMethod,
                const QDateTime &lastCheckTime,
-               const QString &installationUuid,
-               QList<Format> &formatList)
+               const QString &installationUuid)
 {
-  this->currentVersion = currentVersionIn;
-  this->currentVersion.remove("GPSBabel Version ");
-  this->upgradeCheckMethod = checkMethod;
-  this->formatList = &formatList;
+  currentVersion = currentVersionIn;
+  currentVersion.remove("GPSBabel Version ");
+  upgradeCheckMethod = checkMethod;
+//  formatList_ = &formatList;
 
   QDateTime soonestCheckTime = lastCheckTime.addDays(1);
   if (!testing && QDateTime::currentDateTime() < soonestCheckTime) {
@@ -154,12 +156,14 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
   args += "&os_ver=" + getOsVersion();
   args += "&beta_ok=1";   // Eventually to come from prefs.
   args += "&lang=" + QLocale::languageToString(locale.language());
+  args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate);
 
   int j = 0;
-  for (int i = 0; i < formatList.size(); i++) {
-    int rc = formatList[i].getReadUseCount();
-    int wc = formatList[i].getWriteUseCount();
-    QString formatName = formatList[i].getName();
+
+  for (int i = 0; i < formatList_.size(); i++) {
+    int rc = formatList_[i].getReadUseCount();
+    int wc = formatList_[i].getWriteUseCount();
+    QString formatName = formatList_[i].getName();
     if (rc)
       args += QString("&uc%1=rd/%2/%3").arg(j++).arg(formatName).arg(rc);
     if (wc)
@@ -167,7 +171,10 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString &currentV
   }
   if (j)
     args += QString("&uc=%1").arg(j);
-  
+
+  if (false && testing)
+   fprintf(stderr, "Posting %s\n", qPrintable(args));
+
   http->setHost(host, 80);
   httpRequestId = http->request(header, args.toUtf8());
 
@@ -218,6 +225,8 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
 
   QDomNodeList upgrades = document.elementsByTagName("update");
   QUrl downloadUrl;
+  updateStatus_ = updateCurrent;  // Current until proven guilty.
+
   for (unsigned int i = 0; i < upgrades.length(); i++) {
     QDomNode upgradeNode = upgrades.item(i);
     QDomElement upgrade = upgradeNode.toElement();
@@ -236,6 +245,7 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
     upgradeText = upgrade.firstChildElement("overview").text();
     // String compare, not a numeric one.  Server will return "best first".
     if((updateVersion > currentVersion) && updateCandidate) {
+      updateStatus_ = updateNeeded;
       response = tr("A new version of GPSBabel is available.<br />"
         "Your version is %1 <br />"
         "The latest version is %2")
@@ -265,4 +275,8 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error)
   }
 
   upgradeWarningTime = QDateTime(QDateTime::currentDateTime());
+
+  for (int i = 0; i < formatList_.size(); i++) {
+     formatList_[i].zeroUseCounts();
+  }
 }
index 7b5bb148ba224b34a0b6ab796b6e72081dddf7c6..523e7561586dd574028694e826e4775176109add 100644 (file)
@@ -30,7 +30,8 @@ class QHttpResponseHeader;
 class UpgradeCheck : public QObject {
   Q_OBJECT
 public:
-  UpgradeCheck(QWidget *parent = 0);
+  //UpgradeCheck(QWidget *parent = 0);
+  UpgradeCheck(QWidget *parent, QList<Format> &formatList);
   ~UpgradeCheck();
 
   typedef enum {
@@ -42,13 +43,15 @@ public:
   UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion, 
                                             int upgradeCheckMethod,
                                             const QDateTime &lastCheckTime,
-                                            const QString &installationUuid,
-               QList<Format> &formatList
-                                             
+                                            const QString &installationUuid
                                              );
   QDateTime getUpgradeWarningTime() {
     return upgradeWarningTime;
   }
+
+  updateStatus getStatus() {
+    return updateStatus_;
+  }
   static bool isTestMode(void);
 
 protected:
@@ -63,7 +66,8 @@ protected:
   QDateTime upgradeWarningTime;  // invalid time if this object never issued.
   QString getOsName(void);
   QString getOsVersion(void);
-  QList<Format> *formatList;
+  QList<Format> &formatList_;
+  updateStatus updateStatus_;
 
 private slots:
   void httpRequestFinished(int requestId, bool error);